@echo off
setlocal enabledelayedexpansion

:: 指定clang-format的完整路径和参数
set FORMAT_CMD="C:\Program Files\LLVM\bin\clang-format.exe" -i

:: 定义要搜索的目录
set SEARCH_DIRS=Core\Inc Core\Src Core\UnityTest

:: 格式化指定目录下的所有.c和.h文件
for %%d in (%SEARCH_DIRS%) do (
    dir "%%d\" /s /b /a-d | findstr /i "\.[cch]$" > temp_files.txt
    for /f "delims=" %%f in ('type temp_files.txt ^| find /v ""') do (
        echo Formatting file: %%f
        %FORMAT_CMD% "%%f"
    )
    del temp_files.txt
)

echo Formatting complete.
endlocal